package com.nf.sms.utils;

import java.util.List;

/**
 * @AUTHOR CJ
 * <p>
 * *@DATE 2024 - 10 - 18
 * 通用（泛型）分页工具类  -封装分页信息
 *
 */
public class PagerUtil<T> {
    /*
    * 当前页
    * */
    private long currentPage;

    /*
     * 每页显示记录数
     * */
    private int pageCount;


    /*
     * 总记录数
     * */
    private long totalRecordCount;

    /*
    * 总页数
    * */
    private int  totalPageCount;



    /*
    * 页面显示数据
    * */
    List<T> data;

    public long getCurrentPage() {
        return currentPage;
    }
    /*
    * 当前页
    * */
    public void setCurrentPage(int currentPage) {
        if (currentPage <= 0) {
            this.currentPage = 1;
        } else if (currentPage > this.getTotalPageCount()) {
            this.currentPage = this.getTotalPageCount();
        } else {
            this.currentPage = currentPage;
        }
    }

    public int getPageCount() {
        return pageCount;
    }
    /*
     * 每页显示记录数
     * */
    public void setPageCount(int pageCount) {
        this.pageCount = pageCount;
    }

    public long getTotalRecordCount() {
        return totalRecordCount;
    }


    /*
    * 总页数
    * */
    public void setTotalRecordCount(long totalRecordCount) {
        this.totalRecordCount = totalRecordCount;
    }
    public long getTotalPageCount() {
        // 判断总记录数 和 每页记录数是否能整除
        if (this.getTotalRecordCount() % this.getPageCount() == 0) {
            return this.getTotalRecordCount() / this.getPageCount();
        }
        return this.getTotalRecordCount() / this.getPageCount() + 1;
    }
    /*
     * 总记录数
     * */

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    @Override
    public String toString() {
        return "PagerUtil{" +
                "currentPage=" + currentPage +
                ", pageCount=" + pageCount +
                ", totalRecordCount=" + totalRecordCount +
                ", totalPageCount=" + totalPageCount +
                ", data=" + data +
                '}';
    }
}
